<?php
    error_reporting(1);
	ini_set('display_errors', 'on');
    Workerman\Protocols\Http::sessionStart();
    
    // 如果get方式不存在user_id或不存在access_token
    // 则判断session同时存不存在user_id和access_token，不存在则退出登录
    if(!isset($_GET["user_id"]) ||!isset($_GET["access_token"])){
        if(!isset($_SESSION['USER_ID']) && !isset($_SESSION['ACCESS_TOKEN'])){
            Workerman\Protocols\Http::header("Location: ./login.php");
            Workerman\Protocols\Http::end();
        }
    }else{
        $_SESSION['USER_ID'] = $_GET["user_id"];
        $_SESSION['ACCESS_TOKEN'] = $_GET["access_token"];
    }
    
?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>我的生活</title>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1">
    <link rel="shortcut icon" href="/favicon.ico">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">

    <link rel="stylesheet" href="./css/sm.min.css">
    <link rel="stylesheet" href="./css/sm-extend.min.css">

  </head>
   <body>

  <div class="page-group">
      <!-- 你的html代码 -->
      <div class="page page-current" id="page-1581651169664">

          <header class="bar bar-nav">
            <a class="button button-link button-nav pull-left external" href="./login.php">
                退出登录
            </a>
            <h1 class="title">校稿列表</h1>

			<a class="button button-link button-nav pull-right history" style="display: none;" href="./history.php">
                历史稿件

            </a>
          </header>
          <div class="content native-scroll">
              <!-- 这里是页面内容区 -->
              <div class="page-index" id="card_list">
                 
              </div>
          </div>
      </div>
  </div>

    <script type="text/javascript" src="./js/zepto.min.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/sm.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/sm-extend.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/common.js" charset="utf-8"></script>
    <script>

        $(function(){
            var data = {action:"get_poster_list",param:{user_id:"<?php echo $_SESSION['USER_ID'];?>"}};
            var param = {url:"<?php echo $_SESSION["MOBILE_URL"];?>",type:"POST",dataType:"JSON",data:JSON.stringify(data),access_token:"<?php echo $_SESSION['ACCESS_TOKEN'];?>"};
            ajax_request(param,function(result){
                var rtval = result["rtval"];

                // 获取当前身份
                var identity_data = {action:"get_user_data"};
                var identity_param = {url:"<?php echo $_SESSION["MOBILE_URL"];?>",type:"POST",dataType:"JSON",data:JSON.stringify(identity_data),access_token:"<?php echo $_SESSION['ACCESS_TOKEN']?>"};
                ajax_request(identity_param , function(res){
                    rtval.forEach(function(val,index){
                        $("#card_list").append('<div class="card"><div style=""valign="bottom"class="card-header color-white no-border">'+ val["name"]+'<span id="'+val["id"]+'"></span></div><div class="card-content"><div class="card-content-inner"><p class="color-gray">创建日期  '+val["start_time"]+'</p><span>海报数 '+val["amount"]+'</span></div></div><div class="card-footer"><a class="img-select" style="display: none" href="./proofread.php?id='+val["id"]+'&title='+ val["name"]+'    '+val["number"]+'/1"class="link external">更多</a><a href="#" poster_contents_id='+val["id"]+' class=" link submission" style="display:none;">提交</p></div></div>');
                        show_time(val["id"],val["end_time"]);
                    })
                    localStorage.setItem("identity",res.rtval[0].class_level);
                   let identity = localStorage.getItem("identity");

                    if (identity == 1 || identity == 2 || identity == 3){
                        $(".img-select").css("display" , "block");
                        $(".submission").css("display" , "block");
                        $(".history").css("display" , "block");
                    }

                })

            })







			// 提交稿件
            $(document).on('click','.submission', function () {
				let poster_contents_id = $(this).attr("poster_contents_id");
				let parent_html = $(this).parents(".card");
                $.confirm('确定要提交？', '提交后不允许更改', function () {
                    var data = {action:"set_poster_contents",param:{poster_contents_id:poster_contents_id,user_id:"<?php echo $_SESSION['USER_ID'];?>",submission:1}};
                    var param = {url:"<?php echo $_SESSION["MOBILE_URL"];?>",type:"POST",dataType:"JSON",data:JSON.stringify(data),access_token:"<?php echo $_SESSION['ACCESS_TOKEN'];?>"};
                    ajax_request(param,function(result){
                        if(result["errcode"] == 0){
                            $.alert('提交成功');
                            parent_html.remove();
                        }else{
                            $.alert(result["errmsg"],'提交失败');
                        }
                    })

                });
            });
            $.init(); 
        })
    </script>
  

<audio controls="controls" style="display: none;"></audio></body>
</html>